class Solution {
public:
    vector<int> maxInWindows(const vector<int>& num, unsigned int size)
    {
        if(num.empty()||size<1)
            return vector<int>();
        int n=num.size();
        deque<int> index;
        vector<int> res(n-size+1);
        int j=0;
        for(int i=0;i<n;i++){
            while(!index.empty()&&num[i]>=num[index.back()])
                index.pop_back();
            index.push_back(i);
            if(index.front()+size<=i)
                index.pop_front();
            if(i>=size-1)
                res[j++]=num[index.front()];
        }
        return res;
    }
};